package com.framework.controller;

import com.framework.exception.util.RespResult;
import com.framework.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 功能描述: 商户报备控制器
 *
 * @author ck
 * @date 2018/9/11 15:12
 */
@RestController
@Api(value="商户模块",tags={"商户模块"})
@RequestMapping(value = "merchant")
public class MerchantController {

	/**
	 * 代理商基础信息
	 */
	@Autowired
	private MerchantService merchantService;

	/**
	 *  商户报备
	 * @param merchantName 报备商户
	 * @param phone 手机号码
	 * @param sn 终端号
	 * @param model 机具类型
	 * @param token 当前登录人token
	 * @return
	 */
	@PostMapping("user/merchantReport")
	@ApiOperation("商户报备")
	@ApiImplicitParams({
			@ApiImplicitParam(name="merchantName",value="商户名称",dataType="string", paramType = "query" ,required = true),
			@ApiImplicitParam(name="phone",value="手机号码",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="sn",value="机具SN号",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="model",value="机具类型",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="merchantNo",value="商户号",dataType="string", paramType = "query")
	})
	public RespResult merchantReport(String merchantName, String phone, String sn, String model,String token,String merchantNo) {
		merchantService.repMerchant(merchantName, phone, sn, model, token, merchantNo);
		return RespResult.ok();
	}


	/**
	 * 商户查询
	 * @param token
	 * @param types
	 * @param terminalType
	 * @param toDayAmount
	 * @param thisMonthAmount
	 * @param state
	 * @return
	 */
	@GetMapping("user/queryMerchantMap")
	@ApiOperation("商户查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name="types",value="商户时间查询 day:今日 month:当月",dataType="string", paramType = "query" ),
			@ApiImplicitParam(name="terminalType",value="终端类型",dataType="int", paramType = "query" ),
			@ApiImplicitParam(name="toDayAmount",value="昨天交易高低（ASC:升序 DESC：降序",dataType="string", paramType = "query" ,required = true),
			@ApiImplicitParam(name="thisMonthAmount",value="本月交易高低（ASC:升序 DESC：降序",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="state",value="状态（slient:沉默 normal：正常 fine：优质",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="isActivation",value="机器是否激活 1:未激活 2:已激活",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="keywords",value="关键字",dataType="string", paramType = "query",required = true)
	})
	public RespResult queryMerchantMap(String token,String types, Integer terminalType,String toDayAmount,String thisMonthAmount,String state,String isActivation,String keywords) {
		Map<String,Object> map = merchantService.queryMerchantMap(token,types,terminalType,toDayAmount,thisMonthAmount,state,isActivation,keywords);
		return RespResult.ok(map);
	}


	/**
	 * 根据报备id查询商户详情和交易列表
	 * @param token
	 * @param reportId
	 * @return
	 */
	@GetMapping("user/queryMerchantByReportId")
	@ApiOperation("商户详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="用户登录的token",dataType="string", paramType = "query" ),
			@ApiImplicitParam(name="reportId",value="商户id",dataType="int", paramType = "query" ),
	})
	public RespResult queryMerchantByReportId(String token,String reportId) {
		Map<String,Object> map = merchantService.queryMerchantByReportId(token,reportId);
		return RespResult.ok(map);
	}

	/**
	 * 获取商户识别码
	 * @param token
	 * @return
	 */
	@GetMapping("/getMerchantCode")
	@ApiOperation("获取商户识别码")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="用户登录的token",dataType="string", paramType = "query" )
	})
	public RespResult getMerchantCode(String token){
		String code=merchantService.getMerchantCode(token);
		return RespResult.ok().put("merCode",code);
	}



	@PostMapping("user/getYhbMerchant")
	@ApiOperation("获取用户宝推荐商户列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="用户登录的token",dataType="string", paramType = "query" ),
			@ApiImplicitParam(name="state",value="状态",dataType="string", paramType = "query" )
	})
	public RespResult getYhbMerchant(String token,Integer state){
		Map<String, Object> map = merchantService.getYhbMerchant(token, state);
		return RespResult.ok(map);
	}



	@PostMapping("user/verifyMerchant")
	@ApiOperation("审核商户")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="用户登录的token",dataType="string", paramType = "query" ),
			@ApiImplicitParam(name="id",value="主键",dataType="long", paramType = "query" ),
			@ApiImplicitParam(name="sn",value="机具sn",dataType="string", paramType = "query" ),
			@ApiImplicitParam(name="state",value="状态",dataType="integer", paramType = "query" )

	})
	public RespResult verifyMerchant(String token,Long id,String sn,Integer state){
		merchantService.verifyMerchant(token,id,sn,state);
		return RespResult.ok();
	}
}
